package main

import (
	"fmt"
	"fpGrowth/util"
	"math"
	"os"
	"sync"
	"time"
)

func main() {
	var t1 = time.Now()
	var wg = &sync.WaitGroup{}
	var taskChan = make(chan *util.FpTreeTask, 1<<21)

	var resTree = util.ResultTreeNode{}
	var r1 = int(math.Ceil(88162 * 0.001))
	util.Scan("./retail.dat", r1, taskChan, wg, &resTree)

	for i := 0; i < 12; i++ {
		go util.Serve(r1, taskChan, wg)
	}
	wg.Wait()
	close(taskChan)
	fmt.Println(time.Since(t1))
	var r = resTree.ToArray()

	var fil, _ = os.Create("./res.dat")
	var allCount = 0
	for key, val := range r {
		fmt.Println("频繁", key+1, "项集有", len(val))
		allCount += len(val)
	}
	fmt.Println("总共", allCount, "条")
	var rules = util.CalculateStrongRules1(r, 0.1)
	fmt.Println("强规则", len(rules), "条")
	_ = fil.Close()
	var max float64 = -1
	var maxI = 0
	for i := 0; i < len(rules); i++ {
		if rules[i].Support > max {
			maxI = i
			max = rules[i].Support
		}
	}
	fmt.Println(rules[maxI].V1, rules[maxI].V2, rules[maxI].Support)
}
